package com.crazyice.lee.writer;

import lombok.extern.slf4j.Slf4j;
import org.apache.flink.types.Row;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Slf4j
public class SinkToKafka {
    private static Properties properties;
    
    private static void init() {
        properties = new Properties();
        try(InputStream inputStream = SinkToKafka.class.getResourceAsStream("/kafka.properties")) {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void kafkaProducer(Row wordIsCount) {
        init();
        Producer<String, String> producer = new KafkaProducer<>(properties);
        producer.send(new ProducerRecord<>("Test_Topic", String.valueOf(System.currentTimeMillis()), wordIsCount.toString()));
        producer.close();
    }
}